package com.leetcode.algorithm.y22.m07;

import java.util.Arrays;

/**
 * 1356. 根据数字二进制下 1 的数目排序
 * 
 * https://leetcode.cn/problems/sort-integers-by-the-number-of-1-bits/
 * 
 * @author jie.deng
 *
 */
class Question1356Solution01 {
	
	public int[] sortByBits(int[] arr) {
		int[] numArr = new int[arr.length];
		for (int i = 0; i < numArr.length; i++) {
			numArr[i] = arr[i] + Integer.bitCount(arr[i]) * 100000;
		}
		Arrays.sort(numArr);
		for (int i = 0; i < numArr.length; i++) {
			numArr[i] = numArr[i] % 100000;
		}
		return numArr;
	}
    
}